package com.sykj.manage.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sykj.manage.model.DictionaryIndex;
import com.sykj.manage.model.SysDictionary;
import com.sykj.manage.service.SysDictionaryService;
import com.sykj.util.ManageBody;



@Controller
@RequestMapping("/sys")
public class SysDictionaryController {
	
	@Autowired
	SysDictionaryService iSysDictionaryService;
	
	@RequestMapping("/findMtypes")
	@ResponseBody
	public Object findMtypes() {
		List<SysDictionary> mtypes = iSysDictionaryService.findMtypes();
		System.err.println(mtypes);
		return mtypes;
	}
	
	@RequestMapping("/findDictionaryIndexs")
	@ResponseBody
	public ManageBody findDictionaryIndexs(DictionaryIndex dictionaryIndex) {
		List<DictionaryIndex> dictionaryIndexs = iSysDictionaryService.findDictionaryIndexs(dictionaryIndex);
		System.err.println(dictionaryIndexs);
		return ManageBody.getData(dictionaryIndexs.size(), dictionaryIndexs, "");
	}
	
	@RequestMapping("/findDictionarysById")
	@ResponseBody
	public ManageBody findDictionarysById(@RequestParam("dic_index_id")String dic_index_id,SysDictionary sysDictionary) {
		sysDictionary.setDic_index_id(dic_index_id);
		List<SysDictionary> dictionarys = iSysDictionaryService.findDictionarysById(sysDictionary);
		System.err.println(dictionarys);
		return ManageBody.getData(dictionarys.size(), dictionarys, "");
	}
	
	/**
	 * 根据id查询字典标识
	 * @param dic_index_id
	 * @return
	 */
	@RequestMapping("/findDictionaryIndexById")
	@ResponseBody
	public Object findDictionaryIndexById(@RequestParam("dic_index_id")String dic_index_id) {
		DictionaryIndex dictionaryIndex = iSysDictionaryService.findDictionaryIndexById(dic_index_id);
		System.err.println(dictionaryIndex);
		return dictionaryIndex;
	}
	
	/**
	 * 添加字典标识
	 * @param dictionaryIndex
	 * @return
	 */
	@RequestMapping("/addDictionaryIndex")
	@ResponseBody
	public Object addDictionaryIndex(DictionaryIndex dictionaryIndex) {
		Date date = new Date();
		dictionaryIndex.setCreate_time(date);
		int addcnt = iSysDictionaryService.addDictionaryIndex(dictionaryIndex);
		return addcnt;
	}
	
	/**
	 * 修改字典标识
	 * @param dictionaryIndex
	 * @return
	 */
	@RequestMapping("/updDictionaryIndex")
	@ResponseBody
	public Object updDictionaryIndex(DictionaryIndex dictionaryIndex) {
		Date date = new Date();
		dictionaryIndex.setModify_time(date);
		int updcnt = iSysDictionaryService.updDictionaryIndex(dictionaryIndex);
		return updcnt;
	}
	
	/**
	 * 删除字典标识
	 * @param dic_index_ids
	 * @return
	 */
	@RequestMapping("/delDictionaryIndex")
	@ResponseBody
	public Object delDictionaryIndex(@RequestParam("dic_index_ids")String[] dic_index_ids) {
		int delcnt = iSysDictionaryService.delDictionaryIndex(dic_index_ids);
		return delcnt;
	}
	
	//==========================================================
	
	/**
	 * 根据id查询字典
	 * @param dic_id
	 * @return
	 */
	@RequestMapping("/findDictionaryById")
	@ResponseBody
	public Object findDictionaryById(@RequestParam("dic_id")String dic_id) {
		SysDictionary sysDictionary = iSysDictionaryService.findDictionaryById(dic_id);
		System.err.println(sysDictionary);
		return sysDictionary;
	}
	
	/**
	 * 添加字典
	 * @param sysDictionary
	 * @return
	 */
	@RequestMapping("/addDictionary")
	@ResponseBody
	public Object addDictionary(SysDictionary sysDictionary) {
		Date date = new Date();
		sysDictionary.setCreate_time(date);
		int addcnt = iSysDictionaryService.addDictionary(sysDictionary);
		return addcnt;
	}
	
	/**
	 * 修改字典
	 * @param sysDictionary
	 * @return
	 */
	@RequestMapping("/updDictionary")
	@ResponseBody
	public Object updDictionary(SysDictionary sysDictionary) {
		Date date = new Date();
		sysDictionary.setModify_time(date);
		int updcnt = iSysDictionaryService.updDictionary(sysDictionary);
		return updcnt;
	}
	
	/**
	 * 删除字典
	 * @param dic_ids
	 * @return
	 */
	@RequestMapping("/delDictionary")
	@ResponseBody
	public Object delDictionary(@RequestParam("dic_ids")String[] dic_ids) {
		int delcnt = iSysDictionaryService.delDictionary(dic_ids);
		return delcnt;
	}
}
